prepare(" SELECT r.*, es.exam_id, es.selected_subjects, es.start_time, es.end_time, es.time_remaining, e.name as exam_name, e.year as exam_year, e.duration as exam_duration, TIMESTAMPDIFF(MINUTE, es.start_time, es.end_time) as time_taken_minutes FROM results r JOIN exam_sessions es ON r.session_id = es.id JOIN exams e ON es.exam_id = e.id WHERE es.id = ? AND es.student_id = ? "); $stmt->execute([$session_id, $_SESSION['student_id']]); $result = $stmt->fetch(PDO::FETCH_ASSOC); if (!$result) { $_SESSION['error'] = "Result not found or you don't have permission to view it!"; redirect('dashboard.php'); } // Get selected subjects for this session $selected_subjects = json_decode($result['selected_subjects'] ?? '[]', true) ?? []; // Get subject names for display $subject_names = []; if (!empty($selected_subjects)) { $placeholders = str_repeat('?,', count($selected_subjects) - 1) . '?'; $stmt = $pdo->prepare("SELECT name FROM subjects WHERE id IN ($placeholders)"); $stmt->execute($selected_subjects); $subject_names = $stmt->fetchAll(PDO::FETCH_COLUMN); } // Get detailed question analysis for the selected subjects $placeholders = str_repeat('?,', count($selected_subjects) - 1) . '?'; $stmt = $pdo->prepare(" SELECT q.*, s.name as subject_name, sa.selected_answer, sa.is_correct FROM questions q LEFT JOIN subjects s ON q.subject_id = s.id LEFT JOIN student_answers sa ON q.id = sa.question_id AND sa.session_id = ? WHERE q.exam_id = ? AND q.subject_id IN ($placeholders) ORDER BY s.name, q.id "); $stmt->execute(array_merge([$session_id, $result['exam_id']], $selected_subjects)); $questions = $stmt->fetchAll(PDO::FETCH_ASSOC); // Calculate performance metrics $total_questions = $result['total_questions']; $correct_answers = $result['correct_answers']; $questions_attempted = $result['questions_attempted']; $percentage = $result['percentage']; $wrong_answers = $questions_attempted - $correct_answers; $unattempted = $total_questions - $questions_attempted; // Calculate subject-wise performance $subject_performance = []; foreach ($subject_names as $subject_name) { $subject_performance[$subject_name] = [ 'total' => 0, 'correct' => 0, 'attempted' => 0 ]; } foreach ($questions as $question) { $subject_name = $question['subject_name']; if (isset($subject_performance[$subject_name])) { $subject_performance[$subject_name]['total']++; if (!is_null($question['selected_answer'])) { $subject_performance[$subject_name]['attempted']++; if ($question['is_correct']) { $subject_performance[$subject_name]['correct']++; } } } } // Determine performance category and color if ($percentage >= 80) { $performance_category = 'Excellent'; $performance_color = '#27ae60'; $performance_icon = '🎉'; $performance_message = 'Outstanding performance! Keep up the great work!'; } elseif ($percentage >= 60) { $performance_category = 'Good'; $performance_color = '#3498db'; $performance_icon = '👍'; $performance_message = 'Good job! You are on the right track.'; } elseif ($percentage >= 40) { $performance_category = 'Average'; $performance_color = '#f39c12'; $performance_icon = '📊'; $performance_message = 'Average performance. Consider more practice.'; } else { $performance_category = 'Needs Improvement'; $performance_color = '#e74c3c'; $performance_icon = '💪'; $performance_message = 'Keep practicing! You can do better next time.'; } // Calculate time efficiency $time_efficiency = $result['exam_duration'] > 0 ? (($result['exam_duration'] - ($result['time_remaining'] / 60)) / $result['exam_duration']) * 100 : 0; $time_efficiency = min(100, $time_efficiency); // Get student's recent performance for comparison $stmt = $pdo->prepare(" SELECT AVG(percentage) as average_score, COUNT(*) as total_exams FROM results r JOIN exam_sessions es ON r.session_id = es.id WHERE es.student_id = ? AND es.id != ? "); $stmt->execute([$_SESSION['student_id'], $session_id]); $previous_performance = $stmt->fetch(PDO::FETCH_ASSOC); // Calculate improvement $improvement = $previous_performance['average_score'] ? $percentage - $previous_performance['average_score'] : 0; ?> Exam Result - <?php echo htmlspecialchars($result['exam_name']); ?>
← Back to Dashboard

Exam Result

()

%
Score

Correct Answers
Wrong Answers
Unattempted
= 60) { $hours = floor($time_taken / 60); $minutes = $time_taken % 60; echo sprintf('%dh %dm', $hours, $minutes); } else { echo sprintf('%dm', $time_taken); } ?>
Time Taken

Subject-wise Performance

$performance): if ($performance['total'] > 0) { $percentage = $performance['total'] > 0 ? ($performance['correct'] / $performance['total']) * 100 : 0; } else { $percentage = 0; } ?>

% / correct

Score Distribution

Performance Overview

Detailed Question Analysis

$q): $is_correct = $q['is_correct']; $is_attempted = !is_null($q['selected_answer']); $item_class = $is_attempted ? ($is_correct ? 'correct' : 'incorrect') : 'unattempted'; $status_text = $is_attempted ? ($is_correct ? 'Correct' : 'Incorrect') : 'Unattempted'; $status_class = $is_attempted ? ($is_correct ? 'status-correct' : 'status-incorrect') : 'status-unattempted'; ?>
Q:
$q['option_a'], 'B' => $q['option_b'], 'C' => $q['option_c'], 'D' => $q['option_d'] ]; foreach ($options as $letter => $option_text): $is_correct_option = $letter === $q['correct_answer']; $is_selected = $q['selected_answer'] === $letter; $option_class = ''; if ($is_correct_option) { $option_class = 'correct-answer'; } elseif ($is_selected && !$is_correct_option) { $option_class = 'selected-incorrect'; } elseif ($is_selected) { $option_class = 'selected-answer'; } ?>
Note: You selected , but the correct answer is .
Note: You did not attempt this question. The correct answer is .